//
//  ViewController.m
//  HeartDiseaseManage
//
//  Created by 1234 on 2023/2/13.
//

#import "ViewController.h"
//#import <CoreBluetooth/CoreBluetooth.h>
#import "LGCollectionReusableView.h"
@interface ViewController ()<UICollectionViewDelegate,UICollectionViewDataSource>//<CBCentralManagerDelegate,CBPeripheralDelegate>

/**   */
//@property (nonatomic , strong)CBCentralManager *manager;
///**   */
//@property (nonatomic , strong)CBPeripheral *peripheral;

/**   */
@property (nonatomic , strong)UICollectionView *collectionView;
/**   */
@property (nonatomic , strong)NSArray *dataArray;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = RandomColor;
    self.dataArray = @[@"",@"",@"",@"",@""];
    [self.view addSubview:self.collectionView];
}

-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    return 3;
}

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return self.dataArray.count;
}

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
    cell.contentView.backgroundColor = RandomColor;
    return cell;
}

-(UICollectionView *)collectionView{
    if(!_collectionView){
        _collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, Screen_W, Screen_H-topBarHeight) collectionViewLayout:[self grenerateLayout]];
        [_collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"cell"];
        _collectionView.dataSource = self;
        _collectionView.delegate = self;
    }
    return _collectionView;
}

-(UICollectionViewLayout *)grenerateLayout{
    NSCollectionLayoutSpacing *spacing = [NSCollectionLayoutSpacing fixedSpacing:viewPix(8)];
    //1、item
    NSCollectionLayoutSize *itemSize = [NSCollectionLayoutSize sizeWithWidthDimension:[NSCollectionLayoutDimension absoluteDimension:100] heightDimension:[NSCollectionLayoutDimension absoluteDimension:50]];
    NSCollectionLayoutItem *item = [NSCollectionLayoutItem itemWithLayoutSize:itemSize];
    item.edgeSpacing = [NSCollectionLayoutEdgeSpacing spacingForLeading:spacing top:spacing trailing:spacing bottom:spacing];
    //2、group
    NSCollectionLayoutSize *groupSize = [NSCollectionLayoutSize sizeWithWidthDimension:[NSCollectionLayoutDimension absoluteDimension:350] heightDimension:[NSCollectionLayoutDimension absoluteDimension:100]];
    NSCollectionLayoutGroup *group = [NSCollectionLayoutGroup horizontalGroupWithLayoutSize:groupSize subitem:item count:4];
    
    NSCollectionLayoutGroup *group2 = [NSCollectionLayoutGroup verticalGroupWithLayoutSize:groupSize subitem:item count:2];
    
//    group.edgeSpacing = [NSCollectionLayoutEdgeSpacing spacingForLeading:spacing top:spacing trailing:spacing bottom:spacing];
    //3、section
    NSCollectionLayoutSection *section = [NSCollectionLayoutSection sectionWithGroup:group];
    
    
//    NSCollectionLayoutSupplementaryItem *header = [NSCollectionLayoutSupplementaryItem itemWithLayoutSize:groupSize];
//    section.boundarySupplementaryItems = @[header];
    
    UICollectionViewCompositionalLayout *layout = [[UICollectionViewCompositionalLayout alloc] initWithSection:section];
    [layout registerClass:[LGCollectionReusableView class] forDecorationViewOfKind:@"background"];
//    return [[UICollectionViewCompositionalLayout alloc] initWithSectionProvider:^NSCollectionLayoutSection * _Nullable(NSInteger sectionIndex, id<NSCollectionLayoutEnvironment>  _Nonnull layoutEnvironment) {
//        CGFloat width = layoutEnvironment.container.effectiveContentSize.width;
//        CGFloat height = layoutEnvironment.container.effectiveContentSize.height;
//        NSInteger columnCount = [self columnCountWithSection:section width:width];
//    }];
    return layout;
}

- (NSInteger)columnCountWithSection:(NSInteger)section width:(CGFloat)width{
    return 3;
}


//蓝牙状态改变
//-(void)centralManagerDidUpdateState:(CBCentralManager *)central{
//
//}

//搜索外围设备
//-(void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary<NSString *,id> *)advertisementData RSSI:(NSNumber *)RSSI{
//
//}



//连接成功
//-(void)centralManager:(CBCentralManager *)central didConnectPeripheral:(CBPeripheral *)peripheral{
//
//}

//连接失败
//-(void)centralManager:(CBCentralManager *)central didFailToConnectPeripheral:(CBPeripheral *)peripheral error:(NSError *)error{
//
//}

//丢失连接
//-(void)centralManager:(CBCentralManager *)central didDisconnectPeripheral:(CBPeripheral *)peripheral error:(NSError *)error{
//
//}


//获取外围设备的服务、特征
//-(void)peripheral:(CBPeripheral *)peripheral didDiscoverCharacteristicsForService:(CBService *)service error:(NSError *)error{
//
//}

//外围设备数据更新
//-(void)peripheral:(CBPeripheral *)peripheral didUpdateValueForCharacteristic:(CBCharacteristic *)characteristic error:(NSError *)error{
//
//}

//写入数据到蓝牙（要看是否支持数据写入）
//-(void)peripheral:(CBPeripheral *)peripheral didWriteValueForCharacteristic:(nonnull CBCharacteristic *)characteristic error:(nullable NSError *)error{
//
//}

//-(CBCentralManager *)manager{
//    if(!_manager){
//        _manager = [[CBCentralManager alloc]initWithDelegate:self queue:nil];
//    }
//    return _manager;
//}

/*
 
 
 */

@end
